import Pets.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//狗狗属性：编号，名字，种类，性别，年龄，爱吃的实物
//猫属性：编号，名字，种类，性别，年龄，性格
//兔子属性：编号，名字，种类，性别，年龄，体重
public class Shop {
    Scanner imp = new Scanner(System.in);
    private List<Dog> dogs = new ArrayList<>();
    private List<Cat> Cats = new ArrayList<>();
    private List<Rabbit> Rabbits = new ArrayList<>();

//    //获得i号宠物
//    public Dog getDog(int i) {
//        return dogs.get(i);
//    }
//
//    public Cat getCat(int i) {
//        return Cats.get(i);
//    }
//
//    public Rabbit getRabbit(int i) {
//        return Rabbits.get(i);
//    }

    //存入宠物
    public void store(){
        System.out.println("1.录入狗狗  2.录入猫猫  3.录入兔子");
        switch (imp.nextInt()){
            case 1:StoreD();break;
            case 2:StoreC();break;
            case 3:StoreR();break;
            default:
                System.out.println("请输入正确的序号！");
        }
    }
    //存狗
    public void StoreD() {
        Dog d = new Dog();
        System.out.println("输入狗狗名字：");
        d.setName(imp.next());
        System.out.println("输入狗狗种类：");
        d.setKind(imp.next());
        System.out.println("请选择狗狗性别：");
        d.setGender();
        System.out.println("输入狗狗年龄：");
        d.setAge(imp.nextDouble());
        System.out.println("输入狗狗爱吃的食物：");
        d.setFavor(imp.next());
        System.out.println("输入狗狗的价格：");
        d.setPrice(imp.nextInt());
        dogs.add(d);
        d.setNum(dogs.indexOf(d) + 1);
    }

    public void StoreC() {
        Cat d = new Cat();
        System.out.println("输入猫猫名字：");
        d.setName(imp.next());
        System.out.println("输入猫猫种类：");
        d.setKind(imp.next());
        System.out.println("请选择猫猫性别：");
        d.setGender();
        System.out.println("输入猫猫年龄：");
        d.setAge(imp.nextDouble());
        System.out.println("请选择猫猫的性格：");
        d.setCha();
        System.out.println("输入猫猫的价格：");
        d.setPrice(imp.nextInt());
        Cats.add(d);
        d.setNum(Cats.indexOf(d) + 1);
    }

    public void StoreR() {
        Rabbit d = new Rabbit();
        System.out.println("输入兔子名字：");
        d.setName(imp.next());
        System.out.println("输入兔子种类：");
        d.setKind(imp.next());
        System.out.println("请选择兔子性别：");
        d.setGender();
        System.out.println("输入兔子年龄：");
        d.setAge(imp.nextDouble());
        System.out.println("请输入兔子体重：");
        d.setWeight(imp.nextFloat());
        System.out.println("输入兔子的价格：");
        d.setPrice(imp.nextInt());
        Rabbits.add(d);
        d.setNum(Rabbits.indexOf(d) + 1);
    }

    //批量导入
    public void MS() {
        System.out.println("支持批量初始化小动物的种类，性别，年龄，价格！");
        System.out.println("选择要批量初始化的小动物:");
        System.out.println("1.狗狗  2.猫猫  3.兔子");
        switch (imp.nextInt()) {
            case 1:
                MSD();
                break;
            case 2:
                MSC();
                break;
            case 3:
                MSR();
                break;
            default:
                System.out.println("请输入正确的序号！");
        }
    }

    //狗
    public void MSD() {

        System.out.println("请输入需要导入的只数：");
        int count = imp.nextInt();
        System.out.println("请输入狗狗的种类：");
        String kind = imp.next();
        System.out.println("请选择狗狗的性别：");
        System.out.println("1.雄   2.雌");
        int gen = imp.nextInt();
        System.out.println("请输入狗狗的年龄：");
        double age = imp.nextDouble();
        System.out.println("请输入狗狗的价格：");
        int p = imp.nextInt();
        for (int i = 1; i <= count; i++) {
            Dog d = new Dog();
            d.setKind(kind);
            d.setGender(gen);
            d.setAge(age);
            d.setPrice(p);
            System.out.println("输入第" + i + "只狗狗的名字：");
            d.setName(imp.next());
            System.out.println("输入第" + i + "只狗狗爱吃的食物：");
            d.setFavor(imp.next());
            dogs.add(d);
            d.setNum(dogs.indexOf(d) + 1);
        }
    }

    //猫
    public void MSC() {

        System.out.println("请输入需要导入的只数：");
        int count = imp.nextInt();
        System.out.println("请输入猫猫的种类：");
        String kind = imp.next();
        System.out.println("请选择猫猫的性别：");
        System.out.println("1.雄   2.雌");
        int gen = imp.nextInt();
        System.out.println("请输入猫猫的年龄：");
        double age = imp.nextDouble();
        System.out.println("请输入猫猫的价格：");
        int p = imp.nextInt();
        for (int i = 1; i <= count; i++) {
            Cat d = new Cat();
            d.setKind(kind);
            d.setGender(gen);
            d.setAge(age);
            d.setPrice(p);
            System.out.println("输入第" + i + "只猫猫的名字：");
            d.setName(imp.next());
            System.out.println("选择第" + i + "只猫猫的性格：");
            d.setCha();
            Cats.add(d);
            d.setNum(Cats.indexOf(d) + 1);
        }
    }

    //兔子
    public void MSR() {

        System.out.println("请输入需要导入的只数：");
        int count = imp.nextInt();
        System.out.println("请输入兔子的种类：");
        String kind = imp.next();
        System.out.println("请选择兔子的性别：");
        System.out.println("1.雄   2.雌");
        int gen = imp.nextInt();
        System.out.println("请输入兔子的年龄：");
        double age = imp.nextDouble();
        System.out.println("请输入兔子的价格：");
        int p = imp.nextInt();
        for (int i = 1; i <= count; i++) {
            Rabbit d = new Rabbit();
            d.setKind(kind);
            d.setGender(gen);
            d.setAge(age);
            d.setPrice(p);
            System.out.println("输入第" + i + "只兔子的名字：");
            d.setName(imp.next());
            System.out.println("输入第" + i + "只兔子的体重：");
            d.setWeight(imp.nextFloat());
            Rabbits.add(d);
            d.setNum(Rabbits.indexOf(d) + 1);
        }
    }

    //-----------------------------------------------------------------------------------------------------------------------------
    //打印功能
    public void print() {
        showdog();
        showcat();
        showrabbit();
    }

    public void showdog() {
        if(dogs.size()==0) {
            System.out.println("现在还没有狗狗！");
            return;
        }
        System.out.println("狗狗信息：");
        System.out.println("编号 名字  种类  性别  年龄  爱吃的实物  价格");
        for (int i = 0; i < dogs.size(); i++) {
            System.out.print(dogs.get(i).getNum() + "\t");
            System.out.print(dogs.get(i).getName() + " ");
            System.out.print(dogs.get(i).getKind() + "  ");
            System.out.print(dogs.get(i).getGender() + "\t");
            System.out.print(dogs.get(i).getAge() + "\t");
            System.out.print(dogs.get(i).getFavor() + " ");
            System.out.print(dogs.get(i).getPrice() + "\n");
        }
    }

    public void showcat() {
        if(Cats.size()==0) {
            System.out.println("现在还没有猫猫！");
            return;
        }
        System.out.println("猫猫信息：");
        System.out.println("编号 名字  种类  性别  年龄  性格  价格");
        for (int i = 0; i < Cats.size(); i++) {
            System.out.print(Cats.get(i).getNum() + "\t");
            System.out.print(Cats.get(i).getName() + "  ");
            System.out.print(Cats.get(i).getKind() + "  ");
            System.out.print(Cats.get(i).getGender() + "\t");
            System.out.print(Cats.get(i).getAge() + "\t");
            System.out.print(Cats.get(i).getCha() + "  ");
            System.out.print(Cats.get(i).getPrice() + "\n");
        }
    }

    public void showrabbit() {
        if(Rabbits.size()==0) {
            System.out.println("现在还没有兔子！");
            return;
        }
        System.out.println("兔子信息：");
        System.out.println("编号 名字  种类  性别  年龄  体重  价格");
        for (int i = 0; i < Rabbits.size(); i++) {
            System.out.print(Rabbits.get(i).getNum() + "\t");
            System.out.print(Rabbits.get(i).getName() + "  ");
            System.out.print(Rabbits.get(i).getKind() + "  ");
            System.out.print(Rabbits.get(i).getGender() + "\t");
            System.out.print(Rabbits.get(i).getAge() + "\t");
            System.out.print(Rabbits.get(i).getWeight() + "  ");
            System.out.print(Rabbits.get(i).getPrice() + "\n");
        }
    }

    //---------------------------------------------------------------------------------------------------------------------------
    //购买
    public void buy() {
        System.out.println("请选择购买的宠物：");
        System.out.println("1.狗狗  2.猫猫  3.兔子");
        switch (imp.nextInt()) {
            case 1:
                System.out.println("你购买了"+buyD().getName()+"!");
                break;
            case 2:
                System.out.println("你购买了"+buyC().getName()+"!");
                break;
            case 3:
                System.out.println("你购买了"+buyR().getName()+"!");
                break;
            default:
                System.out.println("请输入正确的序号！");
        }
    }

    public Dog buyD() {
        showdog();
        System.out.println("选择要购买的狗狗：");
        int i = imp.nextInt();
        Dog d = dogs.get(--i);
        dogs.remove(i);
        for (; i < dogs.size(); i++) {
            dogs.get(i).setNum(i+1);
        }
        return d;
    }
    public Cat buyC() {
        showcat();
        System.out.println("选择要购买的猫猫：");
        int i = imp.nextInt();
        Cat d = Cats.get(--i);
        Cats.remove(i);
        for (; i < Cats.size(); i++) {
            Cats.get(i).setNum(i+1);
        }
        return d;
    }
        public Rabbit buyR() {
        showrabbit();
        System.out.println("选择要购买的兔子：");
        int i = imp.nextInt();
        Rabbit d = Rabbits.get(--i);
        Rabbits.remove(i);
        for (; i < Rabbits.size(); i++) {
            Rabbits.get(i).setNum(i+1);
        }
        return d;
    }
}
